package com.yale.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;

/**
 * Created by admin on 2017/11/25.
 */
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
//    @Override
//    public void configure(HttpSecurity http) throws Exception {
//        // @formatter:off
//        http.antMatcher("/user").authorizeRequests().anyRequest().authenticated();
//        // @formatter:on
//    }

    @Override
	public void configure(HttpSecurity http) throws Exception {
		// @formatter:off
		http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**")
                .permitAll().anyRequest()
//                .authenticated().and()
//                .formLogin()   //通过formLogin()定义当需要用户登录时候，转到的登录页面。
//                    .loginPage("/login")
//                    .permitAll()
//                    .and()
//                .logout()
//                    .permitAll();
				.authenticated().and().exceptionHandling()
				// 没授权的用户将会跳转到此页面
				.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/"));
				// 增加过滤链，处理要认证的链接
		// @formatter:on
	}


}
